package model;

import metar.MetarParseException;

import metar.WindMetar;

/**
 * Datenmodell f�r Windinformationen
 * 
 * @author Sebastian Althof <get@itnuts.de>
 * @version 1.0.0
 * 
 */
public class WindModel {
	
	/**
	 * Windgeschwindigkeit in Knoten
	 */
	private double speedKnot;
	
	/**
	 * Windrichtung in Grad
	 */
	private int direction;
	
	
	public WindModel() {
		
	}
	
	public WindModel(String windInfo) {
		populate(windInfo);
	}
	
	public WindModel(WeatherModel model) {
		populate(model.getWindDirectionInfo());
	}
	
	
	
	/**
	 * Umsetzung der Stringinformation in das Model
	 * @param windInfo
	 */
	public void populate(String windInfo) {
		//Mathematische "Übersetzung"
		WindMetar wind;
		try {
			wind = new WindMetar().parseParam(windInfo);
			this.setSpeedKnot(wind.getSpeed());
			this.setDirection(wind.getDirection());
		} catch (MetarParseException e) {
			// Fehler wird nicht weitergereicht
//			e.printStackTrace();
		}
	}
	
	
	/**
	 * Windrichtung als "sprechender" Wert
	 */
	public enum DirectionNames {
		NORTH,
		SOUTH,
		EAST,
		WEST,
		NORTH_WEST,
		NORTH_EAST,
		SOUTH_WEST,
		SOUTH_EAST
	}
	
	public DirectionNames getDirectionName() {
		if (direction >= 0 && direction <= 22) {
			return DirectionNames.NORTH;
		}
		else if (direction <= 67) {
			return DirectionNames.NORTH_EAST;
		}
		else if (direction <= 113) {
			return DirectionNames.EAST;
		}
		else if (direction <= 157) {
			return DirectionNames.SOUTH_EAST;
		}
		else if (direction <= 202) {
			return DirectionNames.SOUTH;
		}
		else if (direction <= 247) {
			return DirectionNames.SOUTH_WEST;
		}
		else if (direction <= 292) {
			return DirectionNames.WEST;
		}
		else if (direction <= 337) {
			return DirectionNames.NORTH_WEST;
		}
		
		return null;
	}

	public double getSpeedKnot() {
		return speedKnot;
	}

	public void setSpeedKnot(double speedKnot) {
		this.speedKnot = speedKnot;
	}

	public int getDirection() {
		return direction;
	}

	public void setDirection(int direction) {
		this.direction = direction;
	}
	
	
}
